package com.skp.shaphan.internalStorage;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Version_0_1 implements StructureVersion {

	@Override
	public Version getVersion() {
		return new Version(0, 1);
	}

	@Override
	public void updateDatabase(Connection connection) throws SQLException {
		Statement st = connection.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.FETCH_FORWARD);
		st.execute("create table " + Tables.VersionTable + " (" +
				Fields.Ver_Major +" int," +
				Fields.Ver_Minor +" int)");

		st.execute("create table " + Tables.Dev + " (" +
				Fields.Dev_Enabled +" char(1), " +
				Fields.Dev_AutoLogin +" char(1), " +
				Fields.Dev_AutoConnectionId +" int)");
		ResultSet rs = st.executeQuery("select * from " + Tables.Dev);
		rs.moveToInsertRow();
		rs.updateString(Fields.Dev_Enabled, "N");
		rs.updateString(Fields.Dev_AutoLogin, "N");
		rs.updateInt(Fields.Dev_AutoConnectionId, 0);
		rs.insertRow();
		rs.close();
		st.close();
	}
}
